package saucaca.Database;

import saucaca.Object.SongObject;

import android.content.ContentValues;
import android.database.Cursor;

public class MusicBuilder extends DatabaseBuilder<SongObject> {
	private static final String MUSIC_ID = "songid";
	private static final String MUSIC_NAME = "songname";
	private static final String MUSIC_CODE = "songcode";
	private static final String MUSIC_PIC = "pic";
	private static final String MUSIC_SINGER_NAME = "sname";
	private static final String MUSIC_SINGER_ID = "sid";
	private static final String MUSIC_ISVIEW = "isview";
	private static final String MUSIC_ISDOWN = "isdown";
	private static final String MUSIC_RN = "rn";
	private static final String MUSIC_ALBUM = "album";
//	private static final String MUSIC_LENGTH = "length";
	private static final String MUSIC_URL = "fileurl";
	private static final String MUSIC_LRC_URL = "lrcurl";
	private static final String MUSIC_FORM_NET = "fromnet";

	@Override
	public SongObject build(Cursor c) {
		int columnId = c.getColumnIndex(MUSIC_ID);
		int columnName = c.getColumnIndex(MUSIC_NAME);
		int columnCode = c.getColumnIndex(MUSIC_CODE);
		int columnPic = c.getColumnIndex(MUSIC_PIC);
		int columnSname = c.getColumnIndex(MUSIC_SINGER_NAME);
		int columnSid = c.getColumnIndex(MUSIC_SINGER_ID);
		int columnIsview = c.getColumnIndex(MUSIC_ISVIEW);
		int columnIsdown = c.getColumnIndex(MUSIC_ISDOWN);
		int columnRn = c.getColumnIndex(MUSIC_RN);
		int columnAlbum = c.getColumnIndex(MUSIC_ALBUM);
//		int columnLength = c.getColumnIndex(MUSIC_LENGTH);
		int columnUrl = c.getColumnIndex(MUSIC_URL);
		int columnLrcUrl = c.getColumnIndex(MUSIC_LRC_URL);
		int columnFormNet = c.getColumnIndex(MUSIC_FORM_NET);

		SongObject music = new SongObject();
		music.setSONG_ID(c.getString(columnId));
		music.setTXNAME(c.getString(columnName));
		music.setSONG_CODE(c.getString(columnCode));
		music.setAVATAR(c.getString(columnPic));
		music.setNAME_SINGERS(c.getString(columnSname));
		music.setID_SINGERS(c.getString(columnSid));
		music.setISVIEW(c.getString(columnIsview));
		music.setISDOWN(c.getString(columnIsdown));
		music.setRN(c.getString(columnRn));
		music.setALBUM(c.getString(columnAlbum));
//		music.setLength(c.getInt(columnLength));
		music.setPATCH_FULL(c.getString(columnUrl));
		music.setLYRCIS(c.getString(columnLrcUrl));
		if (c.getInt(columnFormNet) == 0)
			music.setFormNet(false);
		else
			music.setFormNet(true);
		return music;
	}

	@Override
	public ContentValues deconstruct(SongObject t) {
		ContentValues contentValues = new ContentValues();
		contentValues.put(MUSIC_ID, t.getSONG_ID());
		contentValues.put(MUSIC_NAME, t.getTXNAME());
		contentValues.put(MUSIC_CODE, t.getSONG_CODE());
		contentValues.put(MUSIC_PIC, t.getAVATAR());
		contentValues.put(MUSIC_SINGER_NAME, t.getNAME_SINGERS());
		contentValues.put(MUSIC_SINGER_ID, t.getID_SINGERS());
		contentValues.put(MUSIC_ISVIEW, t.getISVIEW());
		contentValues.put(MUSIC_ISDOWN, t.getISDOWN());
		contentValues.put(MUSIC_RN, t.getRN());
		contentValues.put(MUSIC_ALBUM, t.getALBUM());
//		contentValues.put(MUSIC_LENGTH, t.getLength());
		contentValues.put(MUSIC_URL, t.getPATCH_FULL());
		contentValues.put(MUSIC_FORM_NET, t.getFormNet());
		return contentValues;
	}

}
